//------------------------------------------------------------
//  Filename: fusion_top.v
//   
//  Author  : wlduan@gmail.com
//  Revise  : 2016-09-26 12:41
//  Description: 
//   
//  Copyright (C) 2014, YRBD, Inc.                           
//  All Rights Reserved.                                       
//-------------------------------------------------------------
//
`timescale 1ns/1ps
 
module FUSION_TOP  #(
    parameter integer C_S_AXI_DATA_WIDTH     = 32,
    parameter integer C_S_AXI_ADDR_WIDTH     = 16,
    parameter integer C_M_AXI_BURST_LEN      = 64,
    parameter integer C_M_AXI_ID_WIDTH       = 1,
    parameter integer C_M_AXI_ADDR_WIDTH     = 32,
    parameter integer C_M_AXI_DATA_WIDTH     = 32,
    parameter integer C_M_AXI_AWUSER_WIDTH   = 0,
    parameter integer C_M_AXI_WUSER_WIDTH    = 0,
    parameter integer C_M_AXI_BUSER_WIDTH    = 0    
) ( 
    input  wire                                 REGS_AXI_ACLK,
    input  wire                                 REGS_AXI_ARESETN,
    input  wire [C_S_AXI_ADDR_WIDTH-1 : 0     ] REGS_AXI_AWADDR,
    input  wire                                 REGS_AXI_AWVALID,
    output wire                                 REGS_AXI_AWREADY,
    input  wire [C_S_AXI_DATA_WIDTH-1 : 0     ] REGS_AXI_WDATA,
    input  wire [(C_S_AXI_DATA_WIDTH/8)-1 : 0 ] REGS_AXI_WSTRB,
    input  wire                                 REGS_AXI_WVALID,
    output wire                                 REGS_AXI_WREADY,
    output wire [1 : 0                        ] REGS_AXI_BRESP,
    output wire                                 REGS_AXI_BVALID,
    input  wire                                 REGS_AXI_BREADY,
    input  wire [C_S_AXI_ADDR_WIDTH-1 : 0     ] REGS_AXI_ARADDR,
    input  wire                                 REGS_AXI_ARVALID,
    output wire                                 REGS_AXI_ARREADY,
    output wire [C_S_AXI_DATA_WIDTH-1 : 0     ] REGS_AXI_RDATA,
    output wire [1 : 0                        ] REGS_AXI_RRESP,
    output wire                                 REGS_AXI_RVALID,
    input  wire                                 REGS_AXI_RREADY,  
     
    //************* Read channel ***********  
    input  wire                                 VGA_AXI_ACLK,
    input  wire                                 VGA_AXI_ARESETN,   
    output wire [C_M_AXI_ADDR_WIDTH-1 : 0     ] VGA_AXI_ARADDR,
    output wire [7 : 0                        ] VGA_AXI_ARLEN,
    output wire [2 : 0                        ] VGA_AXI_ARSIZE,
    output wire [1 : 0                        ] VGA_AXI_ARBURST,
    output wire [3 : 0                        ] VGA_AXI_ARCACHE,
    output wire                                 VGA_AXI_ARVALID,
    input  wire                                 VGA_AXI_ARREADY,
    output wire [2 : 0                        ] VGA_AXI_ARPROT,
    input  wire [C_M_AXI_DATA_WIDTH-1 : 0     ] VGA_AXI_RDATA,
    input  wire [1 : 0                        ] VGA_AXI_RRESP,
    input  wire                                 VGA_AXI_RLAST,
    input  wire                                 VGA_AXI_RVALID,
    output wire                                 VGA_AXI_RREADY,
    //************* Write channel ***********
    input  wire                                 CAMERA_AXI_ACLK,
    input  wire                                 CAMERA_AXI_ARESETN,
    output wire [C_M_AXI_ID_WIDTH-1 : 0       ] CAMERA_AXI_AWID,
    output wire [C_M_AXI_ADDR_WIDTH-1 : 0     ] CAMERA_AXI_AWADDR,
    output wire [7 : 0                        ] CAMERA_AXI_AWLEN,
    output wire [2 : 0                        ] CAMERA_AXI_AWSIZE,
    output wire [1 : 0                        ] CAMERA_AXI_AWBURST,
    output wire                                 CAMERA_AXI_AWLOCK,
    output wire [2 : 0                        ] CAMERA_AXI_AWPROT,
    output wire [3 : 0                        ] CAMERA_AXI_AWCACHE,
    output wire [3 : 0                        ] CAMERA_AXI_AWQOS,
    output wire [C_M_AXI_AWUSER_WIDTH-1 : 0   ] CAMERA_AXI_AWUSER,
    output wire                                 CAMERA_AXI_AWVALID,
    input  wire                                 CAMERA_AXI_AWREADY,
    output wire [C_M_AXI_DATA_WIDTH-1 : 0     ] CAMERA_AXI_WDATA,
    output wire [C_M_AXI_DATA_WIDTH/8-1 : 0   ] CAMERA_AXI_WSTRB,
    output wire                                 CAMERA_AXI_WLAST,
    output wire [C_M_AXI_WUSER_WIDTH-1 : 0    ] CAMERA_AXI_WUSER,
    output wire                                 CAMERA_AXI_WVALID,
    input  wire                                 CAMERA_AXI_WREADY,
    input  wire [C_M_AXI_ID_WIDTH-1 : 0       ] CAMERA_AXI_BID,
    input  wire [1 : 0                        ] CAMERA_AXI_BRESP,
    input  wire [C_M_AXI_BUSER_WIDTH-1 : 0    ] CAMERA_AXI_BUSER,
    input  wire                                 CAMERA_AXI_BVALID,
    output wire                                 CAMERA_AXI_BREADY,
    //-------------------------------------------------------- 
    input  wire                                 clk_7x_vga,
    input  wire [15:0]                          key_in,
    output wire                                 key_intr,

    output wire                                 rtc_scl,
    inout  wire                                 rtc_sda,

    output wire                                 eeprom_scl,
    inout  wire                                 eeprom_sda,

    output wire                                 adc_scl,
    inout  wire                                 adc_sda,

    output wire                                 dac_sclk,
    output wire                                 dac_sdata,
    output wire                                 dac_load,
    output wire                                 gaoya,
    //-------------------------------------------------------- 
    output wire                                 camerax_pwrdown,
    output wire                                 camerax_resetn,

    input  wire                                 camera0_pclk, 
    input  wire [7:0]                           camera0_yuv , 
    input  wire                                 camera0_h_sync, 
    input  wire                                 camera0_v_sync, 
    output wire                                 camera0_sclk,
    inout  wire                                 camera0_sda ,

    input  wire                                 camera1_pclk, 
    input  wire [7:0]                           camera1_yuv , 
    input  wire                                 camera1_h_sync, 
    input  wire                                 camera1_v_sync, 
    output wire                                 camera1_sclk,
    inout  wire                                 camera1_sda ,
    //-------------------------------------------------------- 
    output wire                                 motor_en,
    output wire                                 motor_rstn,

    output wire                                 motor_stp_l,
    output wire                                 motor_stp_r,
    output wire                                 motor_stp_x,
    output wire                                 motor_stp_y,

    output wire                                 motor_dir_l,
    output wire                                 motor_dir_r,
    output wire                                 motor_dir_x,
    output wire                                 motor_dir_y,
 
    output wire [1:0]                           motor_mod_l,
    output wire [1:0]                           motor_mod_r,
    output wire [1:0]                           motor_mod_x,
    output wire [1:0]                           motor_mod_y,    
    //--------------------------------------------------------
    output wire                                 txout0_p,
    output wire                                 txout0_n,
    output wire                                 txout1_p,
    output wire                                 txout1_n,
    output wire                                 txout2_p,
    output wire                                 txout2_n,
    output wire                                 txout3_p,
    output wire                                 txout3_n,
    output wire                                 txclk_p,
    output wire                                 txclk_n
);      
//--------------------------------------------------------
wire       resetn = REGS_AXI_ARESETN;
wire       c_resetn = REGS_AXI_ARESETN;
wire       video0_only        ;
wire       video1_only        ;
wire[31:0] video0_base_addr   ;
wire[31:0] video1_base_addr   ;
wire[31:0] menu_base_addr     ;
wire[31:0] data_flow_err      ;    
wire[31:0] videos_flow_cnt    ;    
wire[31:0] videos_disp_cnt    ;    

wire[15:0] camera0_cfgAddr    ;
wire[23:0] camera0_cfgData    ;

wire[15:0] camera1_cfgAddr    ;
wire[23:0] camera1_cfgData    ;

wire[7:0]  touch_status       ; 
wire[31:0] disp_pix_cnt       ;
wire[7:0 ] menu_alpha         ;
wire[7:0 ] backlight_period   ;
wire       motor_clk          ;
wire       mm_disp_en         ;
wire       mm_menu_en         ;
wire       mm_bar_hide        ;

wire       xadc_init          ;
wire[15:0] temp_value         ;   
wire[15:0] vpin_value         ;   
wire[15:0] vint_value         ;   
wire[15:0] vaux_value         ;   
wire[15:0] vtmp_value         ;  

wire[31:0] motor_speed        ;
wire[31:0] motor_ctrl_l       ;
wire[31:0] motor_ctrl_r       ;
wire[31:0] motor_ctrl_x       ;
wire[31:0] motor_ctrl_y       ;
 
wire[31:0] fusion_push_state  ; 
wire[31:0] fusion_proc_state  ; 
wire[31:0] fusion_base_x      ; 
wire[7:0]  fusion_pix_black   ; 
wire[31:0] fusion_push_ctrl   ; 
wire[7:0]  fusion_face_sens   ; 
wire[7:0]  fusion_edge_sens   ; 
wire[11:0] fusion_fast_l_x    ; 
wire[11:0] fusion_slow_l_x    ; 
wire[11:0] fusion_fast_r_x    ; 
wire[11:0] fusion_slow_r_x    ; 

wire[31:0] fiber_push_status  ;
wire[31:0] fiber_aux_ctrl     ;

wire       force_pause_l      ;
wire       force_pause_r      ;

wire[31:0] motor_move_l       ;
wire[31:0] motor_move_r       ;
wire[31:0] motor_move_x       ;
wire[31:0] motor_move_y       ;

wire       slow_clk30k_out    ; 
wire       slow_clk1k_out     ; 

wire[11:0] cpu_mem_addrb      ;
wire[31:0] cpu_mem_doutb      ;
wire       cpu_mem_ready0     ;
wire       cpu_mem_ready1     ;

wire[11:0] keyout             ; 
wire[31:0] gaoya_time         ; 
wire[7 :0] gaoya_force        ; 
wire[31:0] gaoya_ctrl_time    ; // fusion prog set
wire[7:0]  gaoya_ctrl_force   ; 
wire[31:0] fusion_force_cfg   ; 
wire[31:0] fusion_time_cfg    ; 

wire[3:0]   phase_l           ;
wire[3:0]   phase_r           ;
wire[3:0]   phase_x           ;
wire[3:0]   phase_y           ; 

wire[15:0] heat_time          ; 
wire[15:0] heat_speed         ; 
wire       heat_mode          ; 
wire       heat_status        ;
wire       heat_test          ; 
    
wire[23:0] beep_cntr          ; 
wire[7:0]  tone_divider       ; 

wire[31:0] rtc_ctrl           ;
wire[15:0] rtc_data_read      ;
wire       rtc_trans_over     ;

wire[31:0] adc_ctrl           ;
wire[15:0] adc_data_read      ;
wire       adc_trans_over     ;
 
wire[15:0] key_out            ;

wire       load_time          ;
wire[31:0] pcf8563_date       ;
wire[31:0] pcf8563_time       ;
wire[31:0] local_date         ;
wire[31:0] local_time         ;

wire[31:0] eeprom_ctrl        ; 
wire[15:0] eeprom_data_read   ; 
wire       eeprom_trans_over  ; 

wire       camera0_video_en   ;
wire[23:0] camera0_dsp_ctrl   ;  
wire[31:0] camera0_base_addr  ;
wire       camera0_base_update;

wire[31:0] camera0_ctrl       ;
wire[15:0] camera0_data_read  ;
wire       camera0_trans_over ;

wire[31:0] camera0_param      ; 
wire[31:0] camera0_error      ; 
wire[15:0] camera0_x_scaler   ;
wire[15:0] camera0_y_scaler   ;
wire[15:0] camera0_x_org_cnt  ; 
wire[15:0] camera0_y_org_cnt  ; 
wire[31:0] camera0_pwr_ctrl   ;

wire[31:0] calibera_edge_x    ;
wire[31:0] calibera_edge_y    ;
wire[31:0] engineer_edge_x    ;
wire[31:0] engineer_edge_y    ;
wire[31:0] engineer_bright    ;

wire       camera1_video_en   ;
wire[23:0] camera1_dsp_ctrl   ;  
wire[31:0] camera1_base_addr  ;
wire       camera1_base_update;

wire[31:0] camera1_ctrl       ;
wire[15:0] camera1_data_read  ;
wire       camera1_trans_over ;

wire[31:0] camera1_param      ;
wire[31:0] camera1_error      ;  
wire[15:0] camera1_x_scaler   ;
wire[15:0] camera1_y_scaler   ;
wire[15:0] camera1_x_org_cnt  ; 
wire[15:0] camera1_y_org_cnt  ; 
wire[31:0] camera1_pwr_ctrl   ;

wire[15:0] camera0_cfg_state  ;
wire[15:0] camera1_cfg_state  ;

wire       camera0_pwrdown    ;
wire       camera0_resetn     ;

wire       camera1_pwrdown    ;
wire       camera1_resetn     ;

wire       soft_pwr_off       ;
wire       force_pwr_off      ;
wire[7:0]  disp_graym         ;

wire[8:0]  coproc0_din        ;
wire       coproc0_wr_en      ;

wire[8:0]  coproc1_din        ;
wire       coproc1_wr_en      ;

wire       camera0_wr_en      ; 
wire[32:0] camera0_din        ; 

wire       camera1_wr_en      ; 
wire[32:0] camera1_din        ; 

wire[31:0] tp_ctrl            ;
wire[15:0] tp_data_read       ;
wire       tp_trans_over      ;
//--------------------------------------------------------
assign {motor_mod_l[1:0],motor_dir_l,motor_stp_l} = phase_l;
assign {motor_mod_x[1:0],motor_dir_x,motor_stp_x} = phase_x;
assign {motor_mod_r[1:0],motor_dir_r,motor_stp_r} = phase_r;
assign {motor_mod_y[1:0],motor_dir_y,motor_stp_y} = phase_y;
//--------------------------------------------------------
assign camerax_pwrdown = camera1_pwrdown&camera0_pwrdown;
assign camerax_resetn  = camera1_resetn&camera0_resetn  ;

assign VGA_AXI_ARPROT = 3'b0;
//--------------------------------------------------------
fusion_reg #(
    .FRAME_BUFFER_BASE  ( 'hAF800000         ) ,
    .FRAME_BUFFER_SIZE  ( 'h00080000         ) ,
    .C_S_AXI_DATA_WIDTH ( C_S_AXI_DATA_WIDTH ) ,
    .C_S_AXI_ADDR_WIDTH ( C_S_AXI_ADDR_WIDTH )
) fusion_reg_inst0(
    .REGS_AXI_ACLK          ( REGS_AXI_ACLK          ) ,
    .REGS_AXI_ARESETN       ( REGS_AXI_ARESETN       ) ,
    .REGS_AXI_AWADDR        ( REGS_AXI_AWADDR        ) ,
    .REGS_AXI_AWVALID       ( REGS_AXI_AWVALID       ) ,
    .REGS_AXI_AWREADY       ( REGS_AXI_AWREADY       ) ,
    .REGS_AXI_WDATA         ( REGS_AXI_WDATA         ) ,
    .REGS_AXI_WSTRB         ( REGS_AXI_WSTRB         ) ,
    .REGS_AXI_WVALID        ( REGS_AXI_WVALID        ) ,
    .REGS_AXI_WREADY        ( REGS_AXI_WREADY        ) ,
    .REGS_AXI_BRESP         ( REGS_AXI_BRESP         ) ,
    .REGS_AXI_BVALID        ( REGS_AXI_BVALID        ) ,
    .REGS_AXI_BREADY        ( REGS_AXI_BREADY        ) ,
    .REGS_AXI_ARADDR        ( REGS_AXI_ARADDR        ) ,
    .REGS_AXI_ARVALID       ( REGS_AXI_ARVALID       ) ,
    .REGS_AXI_ARREADY       ( REGS_AXI_ARREADY       ) ,
    .REGS_AXI_RDATA         ( REGS_AXI_RDATA         ) ,
    .REGS_AXI_RRESP         ( REGS_AXI_RRESP         ) ,
    .REGS_AXI_RVALID        ( REGS_AXI_RVALID        ) ,
    .REGS_AXI_RREADY        ( REGS_AXI_RREADY        ) ,

    .disp_pix_cnt           ( disp_pix_cnt           ) ,
    .menu_alpha             ( menu_alpha             ) ,
    .disp_graym             ( disp_graym             ) ,
        
    .mm_disp_en             ( mm_disp_en             ) ,
    .mm_menu_en             ( mm_menu_en             ) ,
    .mm_bar_hide            ( mm_bar_hide            ) ,
   
    .video0_only            ( video0_only            ) ,
    .video1_only            ( video1_only            ) ,
    .menu_only              ( menu_only              ) ,
    .video0_base_addr       ( video0_base_addr       ) ,
    .video1_base_addr       ( video1_base_addr       ) ,
    .menu_base_addr         ( menu_base_addr         ) ,
    .videos_flow_cnt        ( videos_flow_cnt        ) ,
    .videos_disp_cnt        ( videos_disp_cnt        ) ,

    .camera0_video_en       ( camera0_video_en       ) ,
    .camera0_dsp_ctrl       ( camera0_dsp_ctrl       ) ,
    .camera0_pwr_ctrl       ( camera0_pwr_ctrl       ) ,
    .camera0_ctrl           ( camera0_ctrl           ) ,
    .camera0_data_read      ( camera0_data_read      ) ,
    .camera0_trans_over     ( camera0_trans_over     ) ,
    .camera0_param          ( camera0_param          ) ,
    .camera0_error          ( camera0_error          ) , 
    .camera0_base_update    ( camera0_base_update    ) , 
    .camera0_base_addr      ( camera0_base_addr      ) ,
    .camera0_x_org_cnt      ( camera0_x_org_cnt      ) ,
    .camera0_y_org_cnt      ( camera0_y_org_cnt      ) ,
    .camera0_x_scaler       ( camera0_x_scaler       ) ,
    .camera0_y_scaler       ( camera0_y_scaler       ) ,
    .camera0_cfg_state      ( camera0_cfg_state      ) ,

    .camera1_video_en       ( camera1_video_en       ) ,
    .camera1_dsp_ctrl       ( camera1_dsp_ctrl       ) ,       
    .camera1_pwr_ctrl       ( camera1_pwr_ctrl       ) ,
    .camera1_ctrl           ( camera1_ctrl           ) ,
    .camera1_data_read      ( camera1_data_read      ) ,
    .camera1_trans_over     ( camera1_trans_over     ) ,
    .camera1_param          ( camera1_param          ) ,
    .camera1_error          ( camera1_error          ) ,    
    .camera1_base_update    ( camera1_base_update    ) , 
    .camera1_base_addr      ( camera1_base_addr      ) ,
    .camera1_x_org_cnt      ( camera1_x_org_cnt      ) ,
    .camera1_y_org_cnt      ( camera1_y_org_cnt      ) ,
    .camera1_x_scaler       ( camera1_x_scaler       ) ,
    .camera1_y_scaler       ( camera1_y_scaler       ) ,
    .camera1_cfg_state      ( camera1_cfg_state      ) , 

    .fusion_push_state      ( fusion_push_state      ) ,
    .fusion_proc_state      ( fusion_proc_state      ) ,
    .fusion_base_x          ( fusion_base_x          ) ,
    .fusion_pix_black       ( fusion_pix_black       ) ,
    .fusion_push_ctrl       ( fusion_push_ctrl       ) ,
    .fusion_face_sens       ( fusion_face_sens       ) ,
    .fusion_edge_sens       ( fusion_edge_sens       ) ,
    .fusion_fast_l_x        ( fusion_fast_l_x        ) ,
    .fusion_slow_l_x        ( fusion_slow_l_x        ) ,
    .fusion_fast_r_x        ( fusion_fast_r_x        ) ,
    .fusion_slow_r_x        ( fusion_slow_r_x        ) ,
    .fusion_force_cfg       ( fusion_force_cfg       ) , 
    .fusion_time_cfg        ( fusion_time_cfg        ) ,
    
    .calibera_edge_x        ( calibera_edge_x        ) ,
    .calibera_edge_y        ( calibera_edge_y        ) ,   
    .engineer_edge_x        ( engineer_edge_x        ) ,
    .engineer_edge_y        ( engineer_edge_y        ) ,   
    .engineer_bright        ( engineer_bright        ) ,   
    
    .fiber_push_status      ( fiber_push_status      ) ,
    .fiber_aux_ctrl         ( fiber_aux_ctrl         ) ,

    .cpu_mem_addrb          ( cpu_mem_addrb          ) ,
    .cpu_mem_doutb          ( cpu_mem_doutb          ) ,
    .cpu_mem_ready0         ( cpu_mem_ready0         ) ,
    .cpu_mem_ready1         ( cpu_mem_ready1         ) ,

    .tp_rstn                ( tp_rstn                ) ,
    .tp_waken               ( tp_waken               ) ,
    .tp_ctrl                ( tp_ctrl                ) ,
    .tp_data_read           ( tp_data_read           ) ,
    .tp_trans_over          ( tp_trans_over          ) ,

    .adc_ctrl               ( adc_ctrl               ) ,
    .adc_data_read          ( adc_data_read          ) ,
    .adc_trans_over         ( adc_trans_over         ) ,

    .rtc_ctrl               ( rtc_ctrl               ) ,
    .rtc_data_read          ( rtc_data_read          ) ,
    .rtc_trans_over         ( rtc_trans_over         ) ,

    .eeprom_ctrl            ( eeprom_ctrl            ) ,
    .eeprom_data_read       ( eeprom_data_read       ) ,
    .eeprom_trans_over      ( eeprom_trans_over      ) ,

    .load_time              ( load_time              ) ,
    .pcf8563_date           ( pcf8563_date           ) ,
    .pcf8563_time           ( pcf8563_time           ) ,
    .local_date             ( local_date             ) ,
    .local_time             ( local_time             ) ,

    .plh_keys               ( key_out                ) ,

    .motor_en               ( motor_en               ) ,
    .motor_rstn             ( motor_rstn             ) ,

    .motor_speed            ( motor_speed            ) ,
    .motor_ctrl_l           ( motor_ctrl_l           ) ,
    .motor_ctrl_r           ( motor_ctrl_r           ) ,
    .motor_ctrl_x           ( motor_ctrl_x           ) ,
    .motor_ctrl_y           ( motor_ctrl_y           ) ,
    .gaoya_time             ( gaoya_time             ) ,
    .gaoya_force            ( gaoya_force            ) ,
    .heat_mode              ( heat_mode              ) ,
    .heat_status            ( heat_status            ) ,
    .heat_speed             ( heat_speed             ) ,
    .heat_time              ( heat_time              ) ,
    .heat_test              ( heat_test              ) ,
    .beep_cntr              ( beep_cntr              ) ,
    .tone_divider           ( tone_divider           )        
);
//--------------------------------------------------------
CAMERA_MASTER #(
    .C_M_AXI_BURST_LEN      ( C_M_AXI_BURST_LEN      ) ,
    .C_M_AXI_ID_WIDTH       ( C_M_AXI_ID_WIDTH       ) ,
    .C_M_AXI_ADDR_WIDTH     ( C_M_AXI_ADDR_WIDTH     ) ,
    .C_M_AXI_DATA_WIDTH     ( C_M_AXI_DATA_WIDTH     ) ,
    .C_M_AXI_AWUSER_WIDTH   ( C_M_AXI_AWUSER_WIDTH   ) ,
    .C_M_AXI_WUSER_WIDTH    ( C_M_AXI_WUSER_WIDTH    ) ,
    .C_M_AXI_BUSER_WIDTH    ( C_M_AXI_BUSER_WIDTH    )
)CAMERA_MASTER_inst0( 
    .CAMERA_AXI_ACLK        ( CAMERA_AXI_ACLK        ) ,
    .CAMERA_AXI_ARESETN     ( CAMERA_AXI_ARESETN     ) ,

    .CAMERA_AXI_AWID        ( CAMERA_AXI_AWID        ) ,
    .CAMERA_AXI_AWADDR      ( CAMERA_AXI_AWADDR      ) ,
    .CAMERA_AXI_AWLEN       ( CAMERA_AXI_AWLEN       ) ,
    .CAMERA_AXI_AWSIZE      ( CAMERA_AXI_AWSIZE      ) ,
    .CAMERA_AXI_AWBURST     ( CAMERA_AXI_AWBURST     ) ,
    .CAMERA_AXI_AWLOCK      ( CAMERA_AXI_AWLOCK      ) ,
    .CAMERA_AXI_AWPROT      ( CAMERA_AXI_AWPROT      ) ,
    .CAMERA_AXI_AWCACHE     ( CAMERA_AXI_AWCACHE     ) ,
    .CAMERA_AXI_AWQOS       ( CAMERA_AXI_AWQOS       ) ,
    .CAMERA_AXI_AWUSER      ( CAMERA_AXI_AWUSER      ) ,
    .CAMERA_AXI_AWVALID     ( CAMERA_AXI_AWVALID     ) ,
    .CAMERA_AXI_AWREADY     ( CAMERA_AXI_AWREADY     ) ,
    .CAMERA_AXI_WDATA       ( CAMERA_AXI_WDATA       ) ,
    .CAMERA_AXI_WSTRB       ( CAMERA_AXI_WSTRB       ) ,
    .CAMERA_AXI_WLAST       ( CAMERA_AXI_WLAST       ) ,
    .CAMERA_AXI_WUSER       ( CAMERA_AXI_WUSER       ) ,
    .CAMERA_AXI_WVALID      ( CAMERA_AXI_WVALID      ) ,
    .CAMERA_AXI_WREADY      ( CAMERA_AXI_WREADY      ) ,
    .CAMERA_AXI_BID         ( CAMERA_AXI_BID         ) ,
    .CAMERA_AXI_BRESP       ( CAMERA_AXI_BRESP       ) ,
    .CAMERA_AXI_BUSER       ( CAMERA_AXI_BUSER       ) ,
    .CAMERA_AXI_BVALID      ( CAMERA_AXI_BVALID      ) ,
    .CAMERA_AXI_BREADY      ( CAMERA_AXI_BREADY      ) ,

    .video0_only            ( video0_only            ) ,
    .video1_only            ( video1_only            ) ,
    .videos_flow_err        ( data_flow_err[15:8]    ) ,
    .videos_flow_cnt        ( videos_flow_cnt        ) ,

    .camera0_video_en       ( camera0_video_en       ) ,
    .camera0_base_addr      ( camera0_base_addr      ) ,
    .camera0_base_update    ( camera0_base_update    ) ,

    .camera1_video_en       ( camera1_video_en       ) ,
    .camera1_base_addr      ( camera1_base_addr      ) ,
    .camera1_base_update    ( camera1_base_update    ) ,

    .camera0_wr_en          ( camera0_wr_en          ) ,
    .camera0_din            ( camera0_din            ) ,

    .camera1_wr_en          ( camera1_wr_en          ) ,
    .camera1_din            ( camera1_din            ) 
);
//--------------------------------------------------------
VGA_WRAPPER #(
    .C_M_AXI_BURST_LEN    ( C_M_AXI_BURST_LEN      ),
    .C_M_AXI_ID_WIDTH     ( C_M_AXI_ID_WIDTH       ),
    .C_M_AXI_ADDR_WIDTH   ( C_M_AXI_ADDR_WIDTH     ),
    .C_M_AXI_DATA_WIDTH   ( C_M_AXI_DATA_WIDTH     ),
    .C_M_AXI_AWUSER_WIDTH ( C_M_AXI_AWUSER_WIDTH   ),
    .C_M_AXI_WUSER_WIDTH  ( C_M_AXI_WUSER_WIDTH    ),
    .C_M_AXI_BUSER_WIDTH  ( C_M_AXI_BUSER_WIDTH    )
)VGA_WRAPPER_inst0( 
    .VGA_AXI_ACLK           ( VGA_AXI_ACLK       ) ,
    .VGA_AXI_ARESETN        ( VGA_AXI_ARESETN    ) ,
    .VGA_AXI_ARADDR         ( VGA_AXI_ARADDR     ) ,
    .VGA_AXI_ARLEN          ( VGA_AXI_ARLEN      ) ,
    .VGA_AXI_ARSIZE         ( VGA_AXI_ARSIZE     ) ,
    .VGA_AXI_ARBURST        ( VGA_AXI_ARBURST    ) ,
    .VGA_AXI_ARCACHE        ( VGA_AXI_ARCACHE    ) ,
    .VGA_AXI_ARVALID        ( VGA_AXI_ARVALID    ) ,
    .VGA_AXI_ARREADY        ( VGA_AXI_ARREADY    ) ,
    .VGA_AXI_RDATA          ( VGA_AXI_RDATA      ) ,
    .VGA_AXI_RRESP          ( VGA_AXI_RRESP      ) ,
    .VGA_AXI_RLAST          ( VGA_AXI_RLAST      ) ,
    .VGA_AXI_RVALID         ( VGA_AXI_RVALID     ) ,
    .VGA_AXI_RREADY         ( VGA_AXI_RREADY     ) ,

    .clk_7x_vga             ( clk_7x_vga         ) ,   
    .video0_only            ( video0_only        ) ,
    .video1_only            ( video1_only        ) ,
    .menu_only              ( menu_only          ) ,
    .video0_base_addr       ( video0_base_addr   ) ,
    .video1_base_addr       ( video1_base_addr   ) ,
    .menu_base_addr         ( menu_base_addr     ) ,
    .disp_pix_cnt           ( disp_pix_cnt       ) ,
    .menu_alpha             ( menu_alpha         ) ,
    .disp_graym             ( disp_graym         ) ,
    .backlight_pwm          ( backlight_pwm      ) ,

    .txout0_p               ( txout0_p           ) ,
    .txout0_n               ( txout0_n           ) ,
    .txout1_p               ( txout1_p           ) ,
    .txout1_n               ( txout1_n           ) ,
    .txout2_p               ( txout2_p           ) ,
    .txout2_n               ( txout2_n           ) ,
    .txout3_p               ( txout3_p           ) ,
    .txout3_n               ( txout3_n           ) ,
    .txclk_p                ( txclk_p            ) ,
    .txclk_n                ( txclk_n            ) ,

    .mm_bar_hide            ( mm_bar_hide        ) ,
    .mm_menu_en             ( mm_menu_en         ) ,
    .mm_disp_en             ( mm_disp_en         ) ,

    .videos_disp_cnt        ( videos_disp_cnt    ) ,
    .data_flow_err          ( data_flow_err[7:0] )
);

AUX_WRAPER   
AUX_WRAPER_inst0 ( 
    .clk_100mhz             ( REGS_AXI_ACLK      ) ,
    .reset_n                ( REGS_AXI_ARESETN   ) ,

    .key_in                 ( key_in             ) , 
    .key_out                ( key_out            ) , 
    .key_intr               ( key_intr           ) , 
 
    .adc_ctrl               ( adc_ctrl           ) ,
    .adc_data_read          ( adc_data_read      ) ,
    .adc_trans_over         ( adc_trans_over     ) ,

    .adc_scl                ( adc_scl            ) ,
    .adc_sda                ( adc_sda            ) ,

    .rtc_ctrl               ( rtc_ctrl           ) ,
    .rtc_data_read          ( rtc_data_read      ) ,
    .rtc_trans_over         ( rtc_trans_over     ) ,

    .rtc_scl                ( rtc_scl            ) ,
    .rtc_sda                ( rtc_sda            ) ,

    .eeprom_ctrl            ( eeprom_ctrl        ) ,
    .eeprom_data_read       ( eeprom_data_read   ) ,
    .eeprom_trans_over      ( eeprom_trans_over  ) ,

    .eeprom_scl             ( eeprom_scl         ) ,
    .eeprom_sda             ( eeprom_sda         ) ,

    .load_time              ( load_time          ) ,
    .pcf8563_date           ( pcf8563_date       ) ,
    .pcf8563_time           ( pcf8563_time       ) ,

    .local_date             ( local_date         ) ,
    .local_time             ( local_time         ) ,

    .gaoya_time             ( gaoya_time         ) ,
    .gaoya_force            ( gaoya_force        ) ,
    .gaoya_ctrl_time        ( gaoya_ctrl_time    ) ,
    .gaoya_ctrl_force       ( gaoya_ctrl_force   ) ,
    .motor_clk              ( motor_clk          ) ,

    .dac_sclk               ( dac_sclk           ) ,
    .dac_sdata              ( dac_sdata          ) ,
    .dac_load               ( dac_load           ) ,
    .gaoya                  ( gaoya              )     
);
//---------------------- ----------------------------------
CAMERA_INIT 
CAMERA_INIT_inst0 
(
    .clka                   (  CAMERA_AXI_ACLK   ) ,
    .addra                  (  camera0_cfgAddr   ) ,
    .douta                  (  camera0_cfgData   ) ,
 
    .clkb                   (  CAMERA_AXI_ACLK   ) ,
    .addrb                  (  camera1_cfgAddr   ) ,
    .doutb                  (  camera1_cfgData   )     
);
//--------------------------------------------------------
CAMERA_WRAPPER 
CAMERA_WRAPPER_inst0(  
    .clk_100mhz             ( CAMERA_AXI_ACLK       ) ,
    .resetn                 ( c_resetn              ) ,

    .camera_pwr_ctrl        ( camera0_pwr_ctrl      ) ,
    .camera_dsp_ctrl        ( camera0_dsp_ctrl      ) ,
    .camera_ctrl            ( camera0_ctrl          ) ,
    .camera_data_read       ( camera0_data_read     ) ,
    .camera_trans_over      ( camera0_trans_over    ) ,
    .camera_x_org_cnt       ( camera0_x_org_cnt     ) ,
    .camera_y_org_cnt       ( camera0_y_org_cnt     ) ,
    .camera_x_scaler        ( camera0_x_scaler      ) ,
    .camera_y_scaler        ( camera0_y_scaler      ) ,
    .camera_pix_black       ( fusion_pix_black      ) ,
    .camera_bright          ( engineer_bright[7:0]  ) ,   
    .camera_param           ( camera0_param         ) ,
    .camera_error           ( camera0_error         ) , 
    .camera_video_en        ( camera0_video_en      ) ,       
    .camera_pclk            ( camera0_pclk          ) ,
    .camera_yuv             ( camera0_yuv           ) ,
    .camera_h_sync          ( camera0_h_sync        ) ,
    .camera_v_sync          ( camera0_v_sync        ) ,
    .camera_pwrdown         ( camera0_pwrdown       ) ,
    .camera_resetn          ( camera0_resetn        ) ,
    .camera_sclk            ( camera0_sclk          ) ,
    .camera_sda             ( camera0_sda           ) ,
 
    .rom_cfgAddr            ( camera0_cfgAddr       ) ,
    .rom_cfgData            ( camera0_cfgData       ) ,   
    .ext_cfg_state          ( camera0_cfg_state     ) ,   
    
    .camera_din             ( camera0_din           ) ,
    .camera_wr_en           ( camera0_wr_en         ) ,
    
    .coproc_din             ( coproc0_din           ) ,
    .coproc_wr_en           ( coproc0_wr_en         ) 
);
//--------------------------------------------------------
CAMERA_WRAPPER 
CAMERA_WRAPPER_inst1(  
    .clk_100mhz             ( CAMERA_AXI_ACLK       ) ,
    .resetn                 ( c_resetn              ) ,

    .camera_pwr_ctrl        ( camera1_pwr_ctrl      ) ,
    .camera_dsp_ctrl        ( camera1_dsp_ctrl      ) ,
    .camera_ctrl            ( camera1_ctrl          ) ,
    .camera_data_read       ( camera1_data_read     ) ,
    .camera_trans_over      ( camera1_trans_over    ) ,
    .camera_x_org_cnt       ( camera1_x_org_cnt     ) ,
    .camera_y_org_cnt       ( camera1_y_org_cnt     ) ,
    .camera_x_scaler        ( camera1_x_scaler      ) ,
    .camera_y_scaler        ( camera1_y_scaler      ) ,
    .camera_pix_black       ( fusion_pix_black      ) ,
    .camera_bright          ( engineer_bright[23:16]) ,   
    .camera_param           ( camera1_param         ) ,
    .camera_error           ( camera1_error         ) , 
    .camera_video_en        ( camera1_video_en      ) ,   
    .camera_pclk            ( camera1_pclk          ) ,
    .camera_yuv             ( camera1_yuv           ) ,
    .camera_h_sync          ( camera1_h_sync        ) ,
    .camera_v_sync          ( camera1_v_sync        ) ,
    .camera_pwrdown         ( camera1_pwrdown       ) ,
    .camera_resetn          ( camera1_resetn        ) ,
    .camera_sclk            ( camera1_sclk          ) ,
    .camera_sda             ( camera1_sda           ) ,

    .rom_cfgAddr            ( camera1_cfgAddr       ) ,
    .rom_cfgData            ( camera1_cfgData       ) ,   
    .ext_cfg_state          ( camera1_cfg_state     ) ,          

    .camera_din             ( camera1_din           ) ,
    .camera_wr_en           ( camera1_wr_en         ) ,

    .coproc_din             ( coproc1_din           ) ,
    .coproc_wr_en           ( coproc1_wr_en         ) 
);   


MOTOR_WRAPPER 
MOTOR_WRAPPER_i0(
    .motor_clk              ( motor_clk             ) ,
    .reset_n                ( REGS_AXI_ARESETN      ) ,

    .motor_speed            ( motor_speed           ) ,
    .motor_ctrl_l           ( motor_ctrl_l          ) ,
    .motor_ctrl_r           ( motor_ctrl_r          ) ,
    .motor_ctrl_x           ( motor_ctrl_x          ) ,
    .motor_ctrl_y           ( motor_ctrl_y          ) ,

    .motor_move_l           ( motor_move_l          ) ,
    .motor_move_r           ( motor_move_r          ) ,
    .motor_move_x           ( motor_move_x          ) ,
    .motor_move_y           ( motor_move_y          ) ,

    .force_pause_l          ( force_pause_l         ) ,
    .force_pause_r          ( force_pause_r         ) ,
    .force_pause_x          ( force_pause_x         ) ,
    .force_pause_y          ( force_pause_y         ) ,

    .phase_l                ( phase_l               ) ,
    .phase_r                ( phase_r               ) ,
    .phase_x                ( phase_x               ) ,
    .phase_y                ( phase_y               ) 
);

CO_PROCESSOR_WRAPPER 
CO_PROCESSOR_WRAPPER_inst0( 
    .clk_100mhz           ( CAMERA_AXI_ACLK      ) ,
    .resetn               ( c_resetn             ) ,

    .camera0_x_org_cnt    ( camera0_x_org_cnt    ) ,
    .camera0_y_org_cnt    ( camera0_y_org_cnt    ) ,
    .camera1_x_org_cnt    ( camera1_x_org_cnt    ) ,
    .camera1_y_org_cnt    ( camera1_y_org_cnt    ) ,
 
    .fusion_base_x        ( fusion_base_x        ) ,
    .fusion_pix_black     ( fusion_pix_black     ) ,
    .fusion_fast_l_x      ( fusion_fast_l_x      ) ,
    .fusion_slow_l_x      ( fusion_slow_l_x      ) ,
    .fusion_fast_r_x      ( fusion_fast_r_x      ) ,
    .fusion_slow_r_x      ( fusion_slow_r_x      ) ,
    .fusion_face_sens     ( fusion_face_sens     ) ,
    .fusion_edge_sens     ( fusion_edge_sens     ) ,
    .fusion_push_ctrl     ( fusion_push_ctrl     ) ,
    .fusion_push_state    ( fusion_push_state    ) ,
    .fusion_proc_state    ( fusion_proc_state    ) ,
    .fusion_force_cfg     ( fusion_force_cfg     ) ,
    .fusion_time_cfg      ( fusion_time_cfg      ) ,
    .fusion_proc_intr     ( fusion_proc_intr     ) ,

    .touch_status         ( touch_status         ) ,
    .fiber_push_status    ( fiber_push_status    ) ,
    .fiber_aux_ctrl       ( fiber_aux_ctrl       ) ,
 
    .force_pause_l        ( force_pause_l        ) ,
    .force_pause_r        ( force_pause_r        ) ,

    .gaoya_ctrl_time      ( gaoya_ctrl_time      ) ,
    .gaoya_ctrl_force     ( gaoya_ctrl_force     ) ,

    .motor_move_l         ( motor_move_l         ) ,
    .motor_move_r         ( motor_move_r         ) ,
    
    .calibera_edge_x      ( calibera_edge_x      ) ,
    .calibera_edge_y      ( calibera_edge_y      ) ,
    .engineer_edge_x      ( engineer_edge_x      ) ,
    .engineer_edge_y      ( engineer_edge_y      ) ,

    .coproc0_wr_en        ( coproc0_wr_en        ) ,
    .coproc0_din          ( coproc0_din          ) ,

    .coproc1_wr_en        ( coproc1_wr_en        ) ,
    .coproc1_din          ( coproc1_din          ) ,

    .cpu_mem_addrb        ( cpu_mem_addrb        ) ,
    .cpu_mem_doutb        ( cpu_mem_doutb        ) ,
    
    .cpu_mem_ready0       ( cpu_mem_ready0       ) ,
    .cpu_mem_ready1       ( cpu_mem_ready1       ) 
);  


endmodule
